<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Navajo CPU Visualizer</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

    <script src="http://code.jquery.com/jquery-latest.js"></script>
  
    <script type="text/javascript">
    function infoMessage(message)
    {
     $("#statusMsg").attr('class', '');
     $("#statusMsg").html(message);
    }
    
    function clearMessage()
    {
      infoMessage("");
    }
    
    function errorMessage(message)
    {
      $("#statusMsg").attr('class', 'alert alert-danger');
      $("#statusMsg").html("<span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span> <span class='sr-only'>Error:</span>"+message);
    }
    
    function login()
    {
      $.ajax(
      {
        type: "POST",
        url: "auth.txt",
        data: "login="+$("#login-username").val()+"&pass="+$("#login-password").val(),
        success: function(html){    
          if(html=='authOK')
             $("#loginform").submit();
          else 
            errorMessage("Bad username or password.");
        },
        beforeSend:function()
        {
          infoMessage("Please Wait...");
        }
      });
    }
 
    $().ready(function() {
 						document.getElementById('login-username').addEventListener('keypress', function(e) {

							if(e.keyCode == 13) {
								login();
							}
						});

 						document.getElementById('login-password').addEventListener('keypress', function(e) {

							if(e.keyCode == 13) {
								login();
							}
						});
		});
 
    </script>
  </head>
  <body>
    <div class="container">
      <form style="max-width: 330px; padding: 15px; margin: 0 auto;" method="post" id="loginform">
        <input type="hidden" name="pageId" value="LOGIN"/>
        <h2>Log in to continue</h2>
        <div class="form-group">
          <label for="inputLogin" class="sr-only">Login</label>
          <input type="login" class="form-control" id="login-username" placeholder="Enter login" required="required" autofocus="autofocus" />
        </div>
        <div class="form-group">
          <label for="inputPassword" class="sr-only">Password</label>
          <input type="password" id="login-password" class="form-control" placeholder="Enter password" required="required" />
        </div>
        <button type="button" id="btn-login" class="btn btn-lg btn-primary btn-block" style="margin-bottom:30px;" onclick="login()" >Connect</button>
        <div id="statusMsg" style="display: inline !important;" align="center" role="alert"></div>   
      </form>
    </div>
  </body>
</html>
